#include "usart.h"

void writeString ( USART_TypeDef* USARTx, char* string ) {
  /* Write a character to the USART */
  while ( *string  ) {
    delay ( 30000 );
    USART_SendData(USARTx, *(string++) );
    /* Loop until the end of transmission */
    while(USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET);
    delay ( 30000 );
  }
}

void delay ( int count ) {
  for ( int i = 0; i < count; i ++ );
}
u16 readByte ( USART_TypeDef* USARTx ) {
  while ( USART_GetFlagStatus ( USARTx, USART_FLAG_RXNE ) == RESET );
  u16 data = USART_ReceiveData ( USARTx );
  //delay ( 300 );
  return data;
}
void writeByte ( USART_TypeDef* USARTx, u16 data ) {
  USART_SendData ( USARTx, data );
  while ( USART_GetFlagStatus ( USARTx, USART_FLAG_TXE ) == RESET );
}
